package com.mx.tool.form.factory;

import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.mx.tool.form.window.encryption.Base64Window;
import com.mx.tool.form.window.encryption.EncryptionWindow;
import com.mx.tool.form.window.encryption.HashWindow;

import javax.swing.*;
import java.awt.*;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 08:51
 * @Description:
 */
public class EncryptionFactory {

    private final static HashWindow HASH_WINDOW;
    private final static EncryptionWindow ENCRYPTION_WINDOW;
    private final static Base64Window BASE_64_WINDOW;

    static {
        HASH_WINDOW = new HashWindow();
        ENCRYPTION_WINDOW = new EncryptionWindow();
        BASE_64_WINDOW = new Base64Window();
    }


    /**
     * 添加监听
     *
     * @param hashButton
     * @param encryptionButton
     * @param base64Button
     * @param encryptionPanel
     */
    public static void addActionListeners(JButton hashButton, JButton encryptionButton, JButton base64Button, JPanel encryptionPanel) {
        JPanel hashJPanel = HASH_WINDOW.getContent();
        JPanel encryptionJPanel = ENCRYPTION_WINDOW.getContent();
        JPanel base64JPanel = BASE_64_WINDOW.getContent();
        encryptionPanel.add("hashJPanel", hashJPanel);
        encryptionPanel.add("encryptionJPanel", encryptionJPanel);
        encryptionPanel.add("base64JPanel", base64JPanel);
        hashButton.setForeground(JBColor.GREEN);
        hashButton(hashButton,encryptionButton,base64Button,hashJPanel,encryptionJPanel,base64JPanel);
        encryptionButton(hashButton,encryptionButton,base64Button,hashJPanel,encryptionJPanel,base64JPanel);
        base64Button(hashButton,encryptionButton,base64Button,hashJPanel,encryptionJPanel,base64JPanel);


    }

    private static void hashButton(JButton hashButton, JButton encryptionButton, JButton base64Button, JPanel hashJPanel, JPanel encryptionJPanel, JPanel base64JPanel) {
        hashButton.addActionListener(e -> {
            encryptionJPanel.setVisible(false);
            base64JPanel.setVisible(false);
            encryptionButton.setForeground(JBColor.BLACK);
            base64Button.setForeground(JBColor.BLACK);
            hashJPanel.setVisible(true);
            hashButton.setForeground(JBColor.GREEN);
        });
    }

    private static void encryptionButton(JButton hashButton, JButton encryptionButton, JButton base64Button, JPanel hashJPanel, JPanel encryptionJPanel, JPanel base64JPanel) {
        encryptionButton.addActionListener(e -> {
            hashJPanel.setVisible(false);
            base64JPanel.setVisible(false);
            hashButton.setForeground(JBColor.BLACK);
            base64Button.setForeground(JBColor.BLACK);
            encryptionJPanel.setVisible(true);
            encryptionButton.setForeground(JBColor.GREEN);

        });
    }


    private static void base64Button(JButton hashButton, JButton encryptionButton, JButton base64Button, JPanel hashJPanel, JPanel encryptionJPanel, JPanel base64JPanel) {
        encryptionButton.addActionListener(e -> {
            hashJPanel.setVisible(false);
            base64JPanel.setVisible(false);
            hashButton.setForeground(JBColor.BLACK);
            base64Button.setForeground(JBColor.BLACK);
            encryptionJPanel.setVisible(true);
            encryptionButton.setForeground(JBColor.GREEN);

        });

        base64Button.addActionListener(e -> {
            hashJPanel.setVisible(false);
            encryptionJPanel.setVisible(false);
            hashButton.setForeground(JBColor.BLACK);
            encryptionButton.setForeground(JBColor.BLACK);
            base64JPanel.setVisible(true);
            base64Button.setForeground(JBColor.GREEN);
        });
    }
}
